package com.gwtplatform.samples.hplace.server;

import com.google.inject.Inject;

import com.guit.client.command.action.CommandException;
import com.guit.client.command.action.Handler;
import com.gwtplatform.samples.hplace.shared.GetProductList;
import com.gwtplatform.samples.hplace.shared.GetProductListResult;
import com.gwtplatform.samples.hplace.shared.Product;

import java.util.ArrayList;

public class GetProductListHandler implements Handler<GetProductList, GetProductListResult> {

    private final ProductDatabase database;

    @Inject
    public GetProductListHandler(ProductDatabase database) {
        this.database = database;
    }

    @Override
    public GetProductListResult handle(final GetProductList action) throws CommandException {
        ArrayList<Product> products = database.getMatching(action.getFlags());
        return new GetProductListResult(products);
    }
}
